package com.wd.buycar.view.activity

import androidx.activity.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.GridLayoutManager
import com.wd.buycar.databinding.ActivityNewCarNeiBinding
import com.wd.buycar.view.adapter.BuynewcarwaineiAdapterList
import com.wd.common.base.BaseActivity
import com.wd.common.viewmodel.MyViewModel

class NewCarNeiActivity : BaseActivity<ActivityNewCarNeiBinding, Any>() {
    val viewmodel: MyViewModel by viewModels()
    private var adapter: BuynewcarwaineiAdapterList? = null

    override fun getViewBinding(): ActivityNewCarNeiBinding =
        ActivityNewCarNeiBinding.inflate(layoutInflater)

    override fun initData() {
        val id = this.intent.getIntExtra("id", 0)
        viewmodel.buy_oldcarwainei(id,1)
        viewmodel.buy_oldcarwaineiLiveData.observe(this, Observer {
            adapter = this?.let { it1 -> BuynewcarwaineiAdapterList(it1, it.result) }
            binding.buyNewcarDetailsNeirecy.layoutManager = GridLayoutManager(this,2)
            binding.buyNewcarDetailsNeirecy.adapter = adapter
        })
        val name = intent.getStringExtra("neiname")
        binding.buyNewcarDetailsNeiname.setText(name)
        binding.buyNewcarDetailsNeiname.setOnClickListener {
            finish()
        }
    }
}